import {abstractValidator} from "../validator/abstractValidator";
import {validatorEnum} from "../validator/validatorEnum";
import {validatorManage} from "../validator/validatorManage";
/**
 * Created by ybjaa on 2017/7/3.
 */
export function setValidator_v1(validatorEnumType:validatorEnum,messagePrefix:string="",...obj:any[]){

    let test=0;

    return function (target:any,propertyName:string) {

        test++;

        if(!target[Symbol.for("validator")]){
            target[Symbol.for("validator")]=new Map<string,abstractValidator[]>();
        }

        let map:Map<string,abstractValidator[]>=target[Symbol.for("validator")];

        let validator=validatorManage.GetValidatorClasses(validatorEnumType);

        validator.setMessagePrefix(messagePrefix);
        validator.setParameters.apply(validator,obj);

        if(!map.has(propertyName)){
            map.set(propertyName,[validator]);
        }else {
            map.get(propertyName).push(validator);
        }




    }
    

}